package saucaca.Adapter;

import java.util.ArrayList;
import java.util.List;

import saucaca.Object.SongObject;

import lemon.kenhnhacvn.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class CustomAdapterVideoGridview extends ArrayAdapter<SongObject> {
	Context context;
	List<SongObject> data = new ArrayList<SongObject>();
	ImageLoader imageLoader = ImageLoader.getInstance();
	DisplayImageOptions options;

	// private ImageLoadingListener imageListener;

	public CustomAdapterVideoGridview(Context context, List<SongObject> data) {
		super(context, R.layout.item_album_gridview, data);
		this.context = context;
		this.data = data;

		options = new DisplayImageOptions.Builder().showImageOnFail(R.drawable.ic_default).showStubImage(R.drawable.ic_default).showImageForEmptyUri(R.drawable.ic_default)
				.cacheInMemory().cacheOnDisc().build();

		// imageListener = new ImageDisplayListener();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		RecordHolder holder = null;
		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(R.layout.item_album_gridview, parent, false);
			holder = new RecordHolder();
			holder.txtTitle = (TextView) row.findViewById(R.id.custom_view_album_Title);
			holder.txtArtist = (TextView) row.findViewById(R.id.custom_view_album_artist);
			holder.imageItem = (ImageView) row.findViewById(R.id.custom_view_album_image);
			row.setTag(holder);
		} else {
			holder = (RecordHolder) row.getTag();
		}
		SongObject item = data.get(position);
		holder.txtTitle.setText(item.getTXNAME());
		holder.txtArtist.setText(item.getNAME_SINGERS());
		imageLoader.displayImage(item.getAVATAR(), holder.imageItem, options);
		return row;
	}

	static class RecordHolder {
		TextView txtTitle;
		TextView txtArtist;
		ImageView imageItem;
	}
}
